package com.itheima.prtice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/co03")
public class SessionServlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //需求：第一个Session中设置共享数据，第二个session中得到共享数据
//        HttpSession session = req.getSession();
//        Object name = req.getAttribute("name");
//        resp.getWriter().print(name);
        //----------------------------------
//        HttpSession session = req.getSession();
//        Object name = session.getAttribute("name");
//        resp.getWriter().write(name+"");
        HttpSession session = req.getSession();
        Object username = session.getAttribute("username");
        resp.getWriter().print(username);

    }



    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
